import { Task } from '../types';
import { v4 as uuidv4 } from 'uuid';

// 环保任务数据
export const greenTasks = [
  {
    title: '绿色出行',
    description: '短距离出行选择步行或骑自行车，健康又环保。',
    reward: {
      greenEnergy: 50,
      carbonReduction: 2.5
    }
  },
  {
    title: '随手节能',
    description: '离开房间时关灯，手机充完电立刻拔插头，减少待机耗电。',
    reward: {
      greenEnergy: 30,
      carbonReduction: 1.2
    }
  },
  {
    title: '告别一次性用品',
    description: '随身携带可重复使用的购物袋、水杯和餐具，避免塑料污染。',
    reward: {
      greenEnergy: 40,
      carbonReduction: 1.8
    }
  },
  {
    title: '精简淋浴时间',
    description: '将洗澡时间缩短至5-8分钟，减少热水消耗（每年可省上百公斤碳排放）。',
    reward: {
      greenEnergy: 35,
      carbonReduction: 1.5,
      waterQuality: 0.02
    }
  },
  {
    title: '蔬食日计划',
    description: '今天以蔬菜、豆类为主食，减少红肉摄入。',
    reward: {
      greenEnergy: 45,
      carbonReduction: 3.0
    }
  },
  {
    title: '智慧用水',
    description: '洗手打泡沫时关水龙头，淘米水浇花，一水多用。',
    reward: {
      greenEnergy: 30,
      carbonReduction: 1.2,
      waterQuality: 0.03
    }
  },
  {
    title: '自然晾干代替烘干',
    description: '衣物晾晒代替烘干机，晴天利用阳光杀菌省电。',
    reward: {
      greenEnergy: 35,
      carbonReduction: 2.0
    }
  },
  {
    title: '冰箱空间管理',
    description: '食物放凉后再进冰箱，避免堆积过满（降低制冷能耗）。',
    reward: {
      greenEnergy: 25,
      carbonReduction: 1.0
    }
  },
  {
    title: '旧物新生计划',
    description: '快递盒改造成收纳盒，玻璃瓶用作花瓶，赋予废弃物新用途。',
    reward: {
      greenEnergy: 40,
      carbonReduction: 1.5
    }
  },
  {
    title: '空调智慧使用',
    description: '夏季空调调高1℃（推荐26℃），冬季调低1℃，搭配风扇或增减衣物更舒适。',
    reward: {
      greenEnergy: 50,
      carbonReduction: 2.8
    }
  }
];

// 获取今日随机任务
export const getTodayRandomTasks = (): Task[] => {
  // 真正随机打乱任务数组
  const shuffledTasks = [...greenTasks].sort(() => Math.random() - 0.5);
  
  // 选择前4个任务
  const selectedTasks = shuffledTasks.slice(0, 4);
  
  // 设置截止时间为今天的23:59:59
  const deadline = new Date(new Date().setHours(23, 59, 59, 999));
  
  // 将选择的任务转换为Task类型
  return selectedTasks.map(task => ({
    id: uuidv4(),
    title: task.title,
    description: task.description,
    type: 'daily',
    reward: task.reward,
    progress: 0,
    completed: false,
    deadline,
    criteria: {
      type: 'action',
      target: 1,
      current: 0
    }
  }));
}; 